Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Is there " if .. not in .." in Javascript? I use it in Python but not sure if Javascript has the similar syntax

This function should remove the vowels in string and return string without vowels

function removeVowels(string) {
    var newstring = '';
    var vowels = ['a','e','i','o','u'];
    for ( i in string) {
        if ( i.toLowerCase() not in vowels) { // I know this is wrong but is anything I can use instead of "not in" in JS?
            continue
        } else {
            newstring += i
        }
    }
    return newstring;
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JavaScript does not have a not keyword. Instead, it has a ! for whenever you want to use not. JS's in is NOT the same as python's in. JS uses it for indexes, and if you want the character at the index, you should use of.

I have also made some minor tweaks here and there like not using var and removing the continue statements.

function removeVowels(string) {
    // Instead of using var here, use let and const.
    let newString = '';
    const vowels = ['a','e','i','o','u'];
    // Loop through every character of string
    for (const char of string) {
        // Instead of the continue that you used, you can just simply check if the vowels array includes the specific character.
        if (!vowels.includes(char.toLowerCase())) {
            // This just appends the character to the new string variable
            newString += char;
        }
    }
    return newString;
}
console.log(removeVowels('This string will not have any vowels in it.'));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda